package com.ruoyi.web.controller.system.utils;

import com.ruoyi.common.core.domain.entity.SysDept;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class JointInvestigation {

    public static  List<SysDept> getMen(List<SysDept>allRights){
        List<SysDept>menu=
                allRights.stream()
                        .filter(sysRight -> sysRight.getParentId()==0)
                        .map(sysRight -> {
                            sysRight.setChildren(new ArrayList<>(getchid(sysRight,allRights)));
                            return sysRight;
                        })
                        .collect(Collectors.toList());
        return menu;
    }

    public static List<SysDept> getchid(SysDept root, List<SysDept>allRights){
        return allRights.stream()
                .filter(sysRight -> sysRight.getParentId().equals(root.getDeptId()))
                .map(sysRight -> {
                    sysRight.setChildren(new ArrayList<>(getchidd(sysRight,allRights)));
                    return sysRight;
                })
                .collect(Collectors.toList());
    }

    public static List<SysDept> getchidd(SysDept root,List<SysDept>allRights){
        return allRights.stream()
                .filter(sysRight -> sysRight.getParentId().equals(root.getDeptId()))
                .map(sysRight -> {
                    sysRight.setChildren(new ArrayList<>(getchid(sysRight,allRights)));
                    return sysRight;
                })
                .collect(Collectors.toList());
    }
}